package com.lhn;

import com.lhn.dao.BookDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author lhn
 * @date 2024-08-16 16:45
 */

public class AppForLifeCycle {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("application.xml");

        //注册一个钩子，在 JVM 终止前调用以优雅地关闭上下文。
        ctx.registerShutdownHook();
        BookDao bookDao = (BookDao) ctx.getBean("bookDao");
        bookDao.save();

        //关闭上下文，释放资源并停止所有任务。
//        ctx.close();
    }
}

/**
 控制台输出
 book dao init ...
 book service init ...
 book dao save ...
 book service destroy ...
 book dao destroy ...
*/
